import { request } from '../utils/request.js'
// import request from '../utils/request3.js'
import store from '../store'
import { Toast, Jump } from '../utils/tools.js'
import md5 from 'js-md5'
import { balance } from '@/api/Users.js'


//可售校验运费
export async function beforeCheck(params,data) {
	try {
		let res = await request({
			url: '/Goods/beforeCheck',
			method: "post",
			params,
			data,
			// mask:true
		})
		return res
	} catch (e) {
		return false
	}
}

//商品列表
export async function GetGoodsPage(params) {
	try {
		let res = await request({
			url: '/Goods/GetGoodsPage',
			method: "post",
			params
		})
		if (res.success) {
			res.list.forEach(item => {
				item.bannerpicurl = item.bannerpicurl.split(',')
				item.picurl = item.bannerpicurl[0]
			})
		}
		return res
	} catch (e) {
		return false
	}
}



//商品详情
export async function GoodsFirst(params) {
	try {
		let res = await request({
			url: '/Goods/GoodsFirst',
			method: "post",
			params
		})
		if (res.success) {
			res.data.bannerpicurl = res.data.bannerpicurl.split(',')
			res.data.picurl = res.data.bannerpicurl[0]
		}
		console.log(res)
		return res
	} catch (e) {
		return false
	}
}


//商品分类
export async function GetGoodsTypePage(params) {
	try {
		let res = await request({
			url: '/Goods/GetGoodsTypePage',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}
//购物车
export async function GetShopCar(params) {
	try {
		let res = await request({
			url: '/Goods/GetShopCar',
			method: "post",
			params
		})
		if (res.success) {
			res.list.forEach(item => {
				item.checked = false;
			})

		}
		let arr = res.list || [];
		store.commit('goods/SET_CARTLIST', arr)
		return res
	} catch (e) {
		return false
	}
}

export async function ShopCar_Add(params) {
	try {
		let res = await request({
			url: '/Goods/ShopCar_Add',
			method: "post",
			params
		})
		if (res.success) {
			await GetShopCar();
		}
		return res
	} catch (e) {
		return false
	}
}



//分类详情
export async function GoodsTypeFirst(params) {
	try {
		let res = await request({
			url: '/Goods/GoodsTypeFirst',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}


//删除购物车
export async function ShopCar_Del(data) {
	try {
		let res = await request({
			url: '/Goods/ShopCar_Del',
			method: "post",
			data
		})
		return res
	} catch (e) {
		return false
	}
}

//修改购物车
export async function ShopCar_Edit(params) {
	try {
		let res = await request({
			url: '/Goods/ShopCar_Edit',
			method: "post",
			params,
			mask:true
		})
		return res
	} catch (e) {
		return false
	}
}
//获取我的收藏
export async function getMyGoodsCollect(params) {
	try {
		let res = await request({
			url: '/Goods/getMyGoodsCollect',
			method: "post",
			params
		})
		if (res.success) {
			res.list.forEach(item => {
				item.goodspicurlArr = item.goodspicurl.split(',');
				item.goodspicurl = item.goodspicurlArr[0];
				item.picurl = item.goodspicurlArr[0];
				item.shopicurlArr = item.shopicurl.split(',');
				item.shopicurl = item.shopicurlArr[0];
			})
		}
		return res
	} catch (e) {
		return false
	}
}

//收藏
export async function CollectGoods(params,data) {
	console.log('params===>',params)
	try {
		let res = await request({
			url: '/Goods/CollectGoods',
			method: "post",
			params,
			data
		})
		return res
	} catch (e) {
		return false
	}
}

//获取我的收藏
export async function isCollect(params) {
	try {
		let res = await request({
			url: '/Goods/isCollect',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}

//商品评论 列表
export async function CommentByGoods(params) {
	try {
		let res = await request({
			url: '/Goods/CommentByGoods',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}
//商品评论 写入
export async function Comment(params) {
	try {
		let res = await request({
			url: '/Goods/Comment/Comment',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}

//清空收藏
export async function CollectGoods_Del(params,data) {
	try {
		let res = await request({
			url: '/Goods/CollectGoods_Del',
			method: "post",
			params,
			data
		})
		return res
	} catch (e) {
		return false
	}
}

//按店铺ID查询店铺信息
export async function MallShopInfo(params) {
	try {
		let res = await request({
			url: '/Goods/MallShopInfo',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}

//店铺申请 编辑
export async function ApplyShop(data) {
	try {
		let res = await request({
			url: '/Users/ApplyShop',
			method: "post",
			data
		})
		return res
	} catch (e) {
		return false
	}
}

//店铺信息
export async function Shopinfo() {
	try {
		let res = await request({
			url: '/Users/Shopinfo',
			method: "post",
		})
		return res
	} catch (e) {
		return false
	}
}


//我的代理商品
export async function mygoodsdls(params) {
	try {
		let res = await request({
			url: '/Goods/mygoodsdls',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}